{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc123\n",
      "abc123\n",
      "\n",
      "hello world!\n",
      "你好\n",
      "\n"
     ]
    }
   ],
   "source": [
    "str1 = \"abc123\"\n",
    "\n",
    "str2 = 'abc123'\n",
    "\n",
    "str3 = '''\n",
    "hello world!\n",
    "你好\n",
    "'''\n",
    "\n",
    "print(str1)\n",
    "print(str2)\n",
    "print(str3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello \n",
      "world \n",
      " 你好\n"
     ]
    }
   ],
   "source": [
    "print(\"Hello \\nworld \\n 你好\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "str1 = \"abc123\"\n",
    "print(str1[0])\n",
    "print(str1[-1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "defg\n",
      "nmlk\n",
      "acegikm\n"
     ]
    }
   ],
   "source": [
    "# 切片\n",
    "str2 = \"abcdefghijklmn\"\n",
    "# [M:N:K]\n",
    "# M 起始索引\n",
    "# N 终止索引\n",
    "# K 步长\n",
    "print(str2[3:7])  # defg\n",
    "print(str2[-1:-5:-1])  # nmlk\n",
    "print(str2[::2])  # acegikm\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc123abc123abc123abc123abc123\n"
     ]
    }
   ],
   "source": [
    "print(str1*5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "str1 = \"Python\"\n",
    "str2 = \"Hello\"\n",
    "print(str1 == str2)\n",
    "\n",
    "print(str1 > str2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "str1 = \"He\"\n",
    "str2 = \"Hello\"\n",
    "print(str1 in str2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['java', 'c++', 'vb', 'python', 'swift']\n",
      "张三,李四,王五\n",
      "2\n",
      "hello python!c++, java va!,i love python.\n",
      "HELLO PYTHON!C++, JAVA VA!,I LOVE PYTHON.\n",
      "8\n",
      "2\n",
      "张三\n"
     ]
    }
   ],
   "source": [
    "# find\n",
    "\n",
    "str1 = \"Hello python!c++, java va!,i love python.\"\n",
    "\n",
    "\n",
    "# 从头开始找\n",
    "# print(str1.find(\"python\"))\n",
    "# 从15位置往后找\n",
    "# print(str1.find(\"python\",15))\n",
    "\n",
    "# 2. 替换\n",
    "# print(str1.replace(\"python\",\"JAVA\"))\n",
    "\n",
    "\n",
    "# 3. 分割 split()\n",
    "str1 = \"java,c++,vb,python,swift\"\n",
    "list = str1.split(\",\")\n",
    "print(list)\n",
    "\n",
    "\n",
    "# 4. 链接 join\n",
    "list2 = [\"张三\",\"李四\",\"王五\"]\n",
    "print(\",\".join(list2))\n",
    "\n",
    "# 5. 统计\n",
    "str1 = \"Hello python!c++, java va!,i love python.\"\n",
    "print(str1.count(\"python\"))\n",
    "\n",
    "\n",
    "# 6. 小写 大写  \n",
    "print(str1.lower())\n",
    "print(str1.upper())\n",
    "\n",
    "# 7. \n",
    "str1 =  \"   张三   \"\n",
    "print(len(str1))\n",
    "str1 = str1.strip()\n",
    "print(len(str1))\n",
    "print(str1.strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i love python.And you? I love too! (me)\n",
      "i love python And you  I love too   me \n",
      "['i', 'love', 'python', 'And', 'you', '', 'I', 'love', 'too', '', '', 'me', '']\n",
      "13\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 1.\n",
    "# str = input(\"请输入一段英文\")\n",
    "str = \"i love python.And you? I love too! (me)\"\n",
    "print(str)\n",
    "# 2. 替换\n",
    "# str = str.replace(\".\",\" \")\n",
    "# print(str)\n",
    "# str = str.replace(\"?\",\" \")\n",
    "# str = str.strip()\n",
    "for ch in str:\n",
    "    if ch in \"~!@#$%^&*()_+|}{:\\\"<>?;',./\":\n",
    "        str = str.replace(ch,\" \")\n",
    "print(str)\n",
    "# 3. 分割\n",
    "list = str.split(\" \")\n",
    "print(list)\n",
    "print(len(list))\n",
    "count = 0\n",
    "for s in list:\n",
    "    if s != '':\n",
    "        count = count+1\n",
    "print(count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
